package org.example.service.impl;

import org.example.mapper.BlogMapper;
import org.example.model.BlogInfo;
import org.example.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogMapper blogMapper;

    @Override
    public List<BlogInfo> getBlogList() {
        return blogMapper.getBlogList();
    }

    @Override
    public BlogInfo getBlogDetail(Integer blogId) {
        return blogMapper.getBlogById(blogId);
    }

    @Override
    public Integer addBlog(BlogInfo blogInfo) {
        return blogMapper.insertBlog(blogInfo);
    }

    @Override
    public Boolean update(BlogInfo blogInfo) {
        Integer updateRow = blogMapper.updateBlog(blogInfo);
        if (updateRow == 1) {
            return true;
        }
        return false;
    }

    @Override
    public void deleteBlogById(Integer blogId) {
        BlogInfo blogInfo = new BlogInfo();
        blogInfo.setId(blogId);
        blogInfo.setDeleteFlag(1);
        blogMapper.updateBlog(blogInfo);
    }
}
